package com.example.superoa.model.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONArray;
import com.example.superoa.common.Mail;
import com.example.superoa.model.dao.RbiographicalDao;
import com.example.superoa.model.dao.RinterviewDao;
import com.example.superoa.model.dao.RinterviewerDao;
import com.example.superoa.model.dao.StaffDao;
import com.example.superoa.model.mappers.RbiographicalMapper;
import com.example.superoa.model.mappers.RinterviewMapper;
import com.example.superoa.model.pojos.Position;
import com.example.superoa.model.pojos.Rapply;
import com.example.superoa.model.pojos.Rbiographical;
import com.example.superoa.model.pojos.Rinterview;
import com.example.superoa.model.pojos.Rinterviewer;

@Service
public class RinterviewService {
	
		@Autowired 
		private RinterviewMapper intmapper;
		@Autowired
		private RinterviewDao intdao;
		@Autowired
		private StaffDao s_dao;
		@Autowired
		private RbiographicalMapper o_map;
		@Autowired
		private RbiographicalDao o_dao;
		@Autowired
		private RinterviewerDao er_dao;
		
		Mail m=new Mail();
		//查询所有面试
		public JSONArray findAllview() {
			return intmapper.findAllview();
		}	
		//查询所有未审核面试
		public JSONArray findview() {
			return intmapper.findview();
		}	
		//根据id来执行录用结果
				public void luyong(int id,int rid,int rrid,int jie) {
					Rinterview view=intdao.findById(id).get();
					Rbiographical rb=o_map.findIdd(rid);
					Rinterviewer viewer=er_dao.findById(rrid).get();
					rb.setReasyluyong(jie);
					view.setRiviewqi(jie);
					rb.setRinterviewer(viewer);
					o_dao.save(rb);
					intdao.save(view);
					er_dao.save(viewer);
				}	
		//根据id查询面试
		public JSONArray finByIdview(int riviewid) {
			return intmapper.finByIdview(riviewid);
		}
		//新增面试
		public void jianliinsert(Rinterview interview,Rinterviewer interviewer,int staff_id,Rbiographical biographical,int position_id,int rapplyid) {
			Position position = new Position();
			position.setPositionId(position_id);
			Rapply apply = new Rapply();
			apply.setRapplyid(rapplyid);
			interview.setStaff(s_dao.findById(staff_id).get());
			
			intdao.save(interview);
			interviewer.setRviwername(interview.getRiviewname());
			interviewer.setRinterview(intmapper.rinterview_limit());
			 er_dao.save(interviewer);
			
			biographical.setRinterviewer(intmapper.rinterviewer_limit());
			o_dao.save(biographical);
		}
		//初始化
		public JSONArray selectallinterview(int interview) {
			return intmapper.finByIdview(interview);
		}
		//添加面试结果，修改面试
		public void xiugaiinterview(int riviewid, String riviewoption, String riviewcontent) {
			Rinterview interview = intdao.findById(riviewid).get();
			interview.setRiviewoption(riviewoption);
			interview.setRiviewcontent(riviewcontent);
			intdao.save(interview);
		}
		//查找面试人
		public JSONArray selectRinterviewer() {
			return intmapper.selectRinterviewer();
		}
		//根据应聘职位查询面试官
		public JSONArray selectpositions(Integer id) {
			return intmapper.selectpositions(id);
		}
}